<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ui" uri="http://com.am.tag" %>
<%@ include file="../common.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'userList.jsp' starting page</title>
    <script type="text/javascript" src="${path}/js/public/tree.js"></script>
    <script type="text/javascript">
    	
    	var zTreeObj = null;
    	var rootId = "";
	    $().ready(function(){
			
	    	zTreeObj = createSimpleTree({url:"${path}/tree?method=getDictionaryTree",zTreeId:"tree",expandAll:false,onNodeClick:onNodeClick});
			
			ajax.remoteCall("com.system.dao.DictionaryDao:findRoot",[],function(reply){
				rootId = reply.getResult();
				$("#treeIframe").attr("src","${path}/jsp/dictionary/dictionaryEdit.jsp?id=" + rootId + "&pId=");
    		});
		});
	    
	    function onNodeClick(event,treeId,treeNode)
	    {
	    	var url = "${path}/jsp/dictionary/dictionaryEdit.jsp?id=" + treeNode.id + "&pId=" + treeNode.pId;
	    	$("#treeIframe").attr("src",url);
	    }
	    
	    function updateTree(oprt,treeNode,isSelect)
	    {
	    	switch(oprt)
	    	{
	    		case 'save' : addNode(zTreeObj,treeNode,isSelect); break;
	    		case 'edit' : edit(zTreeObj,treeNode,isSelect); break;
	    		case 'delete' : remove(zTreeObj,treeNode); break;
	    	}
	    	if(oprt == "delete")
	    	{
	    		if(rootId == treeNode.pId)
	    		{
	    			url = "${path}/jsp/dictionary/dictionaryEdit.jsp?id=" + treeNode.pId + "&pId=";
			    	$("#treeIframe").attr("src",url);
	    		}else{
		    		url = "${path}/jsp/dictionary/dictionaryEdit.jsp?id=" + treeNode.pId + "&pId=" +  zTreeObj.getNodeByParam("id",treeNode.pId).id;
			    	$("#treeIframe").attr("src",url);
	    		}
	    	}else{
	    		url = "${path}/jsp/dictionary/dictionaryEdit.jsp?id=" + treeNode.id + "&pId=" + treeNode.pId;
		    	$("#treeIframe").attr("src",url);
	    	}
	    }
    </script>
  </head>
  
  <body>
  	<table style="height: 100%;width: 100%;" cellSpacing="0" cellPadding="0" border="0">
  		<tr>
			<td class="windowTitle">系统管理  &gt; 数据字典</td>
		</tr>
		<tr>
			<td style="width:100%;height:100%;overflow:hidden"  class="windowBody">
				<div id="mess_box" style="width:100%;height:100%;overflow:hidden">
					<table height="100%" width="100%" border="0" cellSpacing="0" cellPadding="0">
						<tr height="100%">
							<td width="180px" align="center" style="padding-left: 5px;border-right:1px dashed #ccc">
								<div style="background-color: white;height: 100%">
									<ul id="tree" class="ztree" style="width:100%;overflow:auto;height:100%"></ul>
								</div>
								
							</td>
							<td align="left" valign="top" style="padding-left:15px;">
								<iframe id="treeIframe" name="treeIframe" frameborder="0" scrolling="auto" width="100%" height="100%" src=""></iframe>
							</td>
						</tr>
					</table>
		    	</div>
		    </td>
		</tr>
  	</table>
  </body>
</html>